# coding=UTF-8
import sqlite3

# 创建连接对象
conn = sqlite3.connect('home-assistant_v2.db')


# 获取日用电量
def dailyEnergy():
    with conn:
        daily_energy = conn.execute(
            "select state_id, entity_id, state from states where entity_id = 'sensor.house_daily_energy' order by state_id desc")
        for i in daily_energy:
            print(i)


# 获取日用电量
def totalEnergy():
    with conn:
        total_energy = conn.execute(
            "select state_id, entity_id, state from states where entity_id = 'sensor.house_total_energy' order by state_id desc")
        for i in total_energy:
            print(i)


# 获取日用电量
def powerConsumption():
    with conn:
        power_consumption = conn.execute(
            "select state_id, entity_id, state from states where entity_id = 'sensor.house_power_consumption' order by state_id desc")
        for i in power_consumption:
            print(i)

dailyEnergy()
totalEnergy()
powerConsumption()
